package com.jy.rhin.support.interceptor;

/**
 * @Description: 在拦截器及AOP中，分别将接口出入参以及SOAP报文原始xml存入上下文，在保存审计信息的时候，从上下文获取数据，打包成审计记录
 * @Author: lww
 * @Date: 2022/5/20 11:03
 */
public class WsXmlThreadLocal {

    private WsXmlThreadLocal() {
    }

    /**
     * 保存webService接口出入参的原始xml
     */
    private static final ThreadLocal<String> XML_LOCAL = new ThreadLocal<>();
    /**
     * 保存webService接口出入参的对象
     */
    private static final ThreadLocal<Object> DATA_LOCAL = new ThreadLocal<>();
    
    //订阅接口出口审计需要得到入参判断事件类型
    private static final ThreadLocal<Object> REQUEST_DATA = new ThreadLocal<>();

    private static final ThreadLocal<Boolean> HAS_CACHED = new ThreadLocal<>();
    
    //方法名,例：DocumentSubAndPubPortImpl.documentSubscribe
    private static final ThreadLocal<String> METHOD= new ThreadLocal<>();

    public static Object getREQUEST_DATA() {
		return REQUEST_DATA.get();
	}
    
    public static void setREQUEST_DATA(Object data) {
    	REQUEST_DATA.set(data);
	}
    
    public static String getMETHOD() {
		return METHOD.get();
	}
    
    public static void setMETHOD(String shijian) {
    	METHOD.set(shijian);
	}

	public static void setXml(String xmlStr) {
        XML_LOCAL.set(xmlStr);
    }

    public static String getXml() {
        return XML_LOCAL.get();
    }

    public static void setData(Object data) {
        DATA_LOCAL.set(data);
        HAS_CACHED.set(true);
    }

    public static Object getData() {
        return DATA_LOCAL.get();
    }

    public static boolean hasCached() {
        return Boolean.TRUE.equals(HAS_CACHED.get());
    }

    public static void clear() {
        XML_LOCAL.remove();
        DATA_LOCAL.remove();
        HAS_CACHED.remove();
        METHOD.remove();
        REQUEST_DATA.remove();
    }

}
